import { format } from "date-fns";
import _ from "lodash";

/**
 * 时间格式化
 * @param {*} value
 * @param {*} format_str
 * @returns
 */
export function dateFmt(value, format_str = "yyyy/MM/dd HH:mm:ss") {
  if (!value) return "";
  if (!_.isString(value)) return "";
  if (value.startsWith("0001")) return "";
  // 将日期字符串中的 "-" 替换为 "/"
  value = value.replace(/-/g, "/").replace("T", " ");
  return format(new Date(value), format_str);
}
/**
 * 对象转数组对象
 */
export function transformerObject(obj) {
  if (typeof obj !== "object") return;
  const newobj = _.mapValues(obj, (value, key) => ({
    ParameterName: key,
    ParameterValue: value,
  }));
  const result = Object.values(newobj);
  return result;
}
